package com.zheng.hospital.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zheng.hospital.common.result.CommonResult;
import com.zheng.hospital.model.user.UserInfo;
import com.zheng.hospital.service.UserService;
import com.zheng.hospital.vo.user.UserInfoQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 查询用户列表
     * @param page
     * @param limit
     * @param userInfoQueryVo
     * @return
     */
    @GetMapping("/{page}/{limit}")
    public CommonResult list(@PathVariable Long page, @PathVariable Long limit, UserInfoQueryVo userInfoQueryVo) {
        Page<UserInfo> pageParam = new Page<>(page, limit);
        IPage<UserInfo> pageModel = userService.selectPage(pageParam, userInfoQueryVo);
        return CommonResult.ok(pageModel);
    }

    /**
     * 用户锁定
     * @param userId
     * @param status
     * @return
     */
    @GetMapping("lock/{userId}/{status}")
    public CommonResult lock(@PathVariable Long userId,@PathVariable Integer status) {
        userService.lock(userId,status);
        return CommonResult.ok();
    }

    /**
     * 用户详情
     * @param userId
     * @return
     */
    @GetMapping("show/{userId}")
    public CommonResult show(@PathVariable Long userId) {
        Map<String,Object> map = userService.show(userId);
        return CommonResult.ok(map);
    }

    /**
     * 认证审批
     * @param userId
     * @param authStatus
     * @return
     */
    @GetMapping("approval/{userId}/{authStatus}")
    public CommonResult approval(@PathVariable Long userId,@PathVariable Integer authStatus) {
        userService.approval(userId,authStatus);
        return CommonResult.ok();
    }
}
